<template>
  <el-container class="app-container">
    <!-- 侧边栏 -->
    <el-aside :width="isCollapse ? '64px' : '200px'" class="sidebar">
      <!-- Logo区域 -->
      <div class="logo">
        <span v-if="!isCollapse">管理系统</span>
        <el-icon v-else><Monitor /></el-icon>
      </div>

      <!-- 导航菜单 -->
      <el-menu
          :default-active="activeMenu"
          class="el-menu-vertical"
          :collapse="isCollapse"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF">

        <el-menu-item index="1">
          <el-icon><HomeFilled /></el-icon>
          <span>首页</span>
        </el-menu-item>

        <el-sub-menu index="2">
          <template #title>
            <el-icon><Document /></el-icon>
            <span>数据管理</span>
          </template>
          <el-menu-item index="2-1">数据列表</el-menu-item>
          <el-menu-item index="2-2">数据分析</el-menu-item>
        </el-sub-menu>

        <el-menu-item index="3" @click="router.push('/user-management')">
          <el-icon><User /></el-icon>
          <span>用户管理</span>
        </el-menu-item>

        <el-sub-menu index="4">
          <template #title>
            <el-icon><Document /></el-icon>
            <span>城市管理</span>
          </template>
          <el-menu-item index="4-1" @click="router.push('/city-management')">城市详情</el-menu-item>
          <el-menu-item index="4-2" @click="router.push('/food-management')">城市美食</el-menu-item>
          <el-menu-item index="4-3" @click="router.push('/travelogue-management')">城市景点</el-menu-item>
        </el-sub-menu>

        <el-menu-item index="4">
          <el-icon><Setting /></el-icon>
          <span>系统设置</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <!-- 头部区域 -->
      <el-header class="header">
        <div class="header-left">
          <el-icon class="collapse-btn" @click="toggleCollapse">
            <Fold v-if="!isCollapse" />
            <Expand v-else />
          </el-icon>
          <div class="breadcrumb">
            <el-breadcrumb>
              <el-breadcrumb-item>首页</el-breadcrumb-item>
              <el-breadcrumb-item>控制台</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
        </div>

        <div class="header-right">
          <!-- 搜索框 -->
          <el-input
              v-model="searchText"
              placeholder="搜索..."
              class="search-input"
              prefix-icon="Search"
          />

          <!-- 消息通知 -->
          <el-badge :value="3" class="notice-badge">
            <el-icon class="header-icon"><Bell /></el-icon>
          </el-badge>

          <!-- 全屏按钮 -->
          <el-icon class="header-icon"><FullScreen /></el-icon>

          <!-- 用户头像和下拉菜单 -->
          <el-dropdown trigger="click">
            <div class="avatar-container">
              <el-avatar :size="30" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <span class="username">管理员</span>
              <el-icon><CaretBottom /></el-icon>
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 主要内容区域 -->
      <el-main class="main">
        <!-- 这里通常是路由视图 router-view -->
        <!-- 使用路由视图 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  HomeFilled,
  Document,
  Setting,
  User,
  Bell,
  Search,
  FullScreen,
  CaretBottom,
  Fold,
  Expand,
  Monitor
} from '@element-plus/icons-vue'

// 控制侧边栏折叠状态
const isCollapse = ref(false)
const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value
}

const router = useRouter()

// 当前激活菜单
const activeMenu = ref('1')

// 搜索文本
const searchText = ref('')
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
.app-container {
  height: 100vh;
  width: 100%;
}

/* 侧边栏样式 */
.sidebar {
  background-color: #304156;
  transition: width 0.3s;
  overflow: hidden;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2b3649;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
}

.el-menu-vertical {
  border-right: none;
}

/* 头部样式 */
.header {
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
}

.header-left {
  display: flex;
  align-items: center;
}

.collapse-btn {
  font-size: 20px;
  cursor: pointer;
  margin-right: 15px;
}

.header-right {
  display: flex;
  align-items: center;
}

.search-input {
  width: 180px;
  margin-right: 15px;
}

.header-icon {
  font-size: 18px;
  cursor: pointer;
  margin: 0 10px;
  color: #606266;
}

.notice-badge {
  margin-right: 10px;
}

.avatar-container {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.username {
  margin: 0 5px;
  font-size: 14px;
  color: #606266;
}

/* 主内容区样式 */
.main {
  background-color: #f0f2f5;
  padding: 20px;
}

.content {
  background-color: #fff;
  padding: 20px;
  border-radius: 4px;
}
.table-card {
  margin-bottom: 20px;
  width: 100%;
}

.el-table {
  width: 100%;
}
</style>